﻿//********************************************************************************//
//创建日期：<创建日期，2016-05-27>
//创建作者：<郭登杰>
//功能说明：来函公共控件-并户申请信息
//********************************************************************************//
using BLL.Access;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;
using Entity;
using BLL;
using DevExpress.Web;

namespace Web.Controls.LAIHAN
{
    public partial class UCLHShenQingXX_BHQS : System.Web.UI.UserControl, IUCLHOperate
    {
        #region 属性

        /// <summary>
        /// 来函类型
        /// </summary>
        public eLaiHanLX LaiHanLX { get; set; }

        /// <summary>
        /// 来函流程
        /// </summary>
        public eLaiHanLCBH LaiHanLC { get; set; }

        /// <summary>
        /// 记录查询结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        /// <summary>
        /// 记录站点
        /// </summary>
        public string ZhanDianBH
        {
            get
            {
                return Convert.ToString(ViewState["ZhanDianBH"]);
            }
            set
            {
                ViewState["ZhanDianBH"] = value;
            }
        }

        /// <summary>
        /// 记录管理块
        /// </summary>
        public string GuanLiKBH
        {
            get
            {
                return Convert.ToString(ViewState["GuanLiKBH"]);
            }
            set
            {
                ViewState["GuanLiKBH"] = value;
            }
        }

        /// <summary>
        /// 并户后的用户号
        /// </summary>
        public string YongHuH
        {
            get
            {
                return this.txtYongHuH.Text;
            }
        }
        /// <summary>
        /// 是否详细信息
        /// </summary>
        public bool IsXXXX { get; set; }

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }
            SetDisplay();
        }

        /// <summary>
        /// 移除
        /// </summary>
        protected void lnbDel_Command(object sender, CommandEventArgs e)
        {
            //清除结果集中对应记录
            for (int i = 0; i < this.dtSource.Rows.Count; i++)
            {
                if (this.dtSource.Rows[i]["S_YONGHUH"].ToString() == e.CommandArgument.ToString())
                {
                    this.dtSource.Rows.RemoveAt(i);
                }
            }
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }

       

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            //获取合同号
            string hetongh = BusinessTool.GetHeTongH(this.txtYongHuH.Text);
            e.Result = e.Parameter + "|0|" + hetongh;
        }

        #endregion

        #region 方法

        /// <summary>
        /// 配置控件
        /// </summary>
        public void InitControl()
        {
            PageTools.QSLoadCombox(this.cmbZhuGuanBM, PageTools.eLoadType.管理部门QS, null, null);
            PageTools.QSLoadCombox(this.cmbHangYeLX, PageTools.eLoadType.行业分类QS, null, null);
            PageTools.QSLoadCombox(this.cmbXingZhengQ, PageTools.eLoadType.行政区QS, null, null);
            PageTools.QSLoadCombox(this.cmbHuanXianBJ, PageTools.eLoadType.环线标记QS, null, null);
            PageTools.QSLoadCombox(this.cmbLiuYu, PageTools.eLoadType.流域QS, null, null);
            PageTools.QSLoadCombox(this.cmbQuShuiYT, PageTools.eLoadType.取水用途QS, null, null);
            PageTools.QSLoadCombox(this.cmbShuiLiFP, PageTools.eLoadType.水利分片QS, null, null);
            PageTools.QSLoadCombox(this.cmbShuiZiYFQ, PageTools.eLoadType.水资源分区QS, null, null);
            PageTools.QSLoadCombox(this.cmbYWY, PageTools.eLoadType.业务员QS, null, null);
            this.cmbZhuangBiaoJL.SelectedIndex = 0;
            PageTools.SetDisabled(this.txtHeTongH, false);
        }

        /// <summary>
        /// 设置控件启禁用
        /// </summary>
        /// <param name="enabled"></param>
        private void SetEnabled(bool enabled)
        {
            this.txtShouLiRQ.Enabled = enabled;
            this.txtYeWuY.Enabled = enabled;
            this.txtDiZhi.Enabled = enabled;
            this.txtHeTongH.Enabled = enabled;
            this.txtKaiHuM.Enabled = enabled;
            this.txtKaiHuYH.Enabled = enabled;
            this.txtKaiHuZH.Enabled = enabled;
            this.txtLianXiBM.Enabled = enabled;
            this.txtLianXiDH.Enabled = enabled;
            this.txtLianXiR.Enabled = enabled;
            this.txtYeWuY.Enabled = enabled;
            this.txtYongHuH.Enabled = enabled;
            this.txtYongHuM.Enabled = enabled;
            this.txtYouBian.Enabled = enabled;
            this.txtYSJ.Enabled = enabled;
            this.cmbHangYeLX.Enabled = enabled;
            this.cmbXingZhengQ.Enabled = enabled;
            this.cmbYWY.Enabled = enabled;
            this.cbTuoShou.Enabled = enabled;
            this.txtCaiWuDZ.Enabled = enabled;
            this.txtCaiWuHM.Enabled = enabled;
            this.txtCaiWuYB.Enabled = enabled;
            this.cmbHuanXianBJ.Enabled = enabled;
            this.cmbLiuYu.Enabled = enabled;
            this.cmbQuShuiYT.Enabled = enabled;
            this.cmbShuiLiFP.Enabled = enabled;
            this.cmbShuiZiYFQ.Enabled = enabled;
            this.cmbZhuangBiaoJL.Enabled = enabled;
            this.cmbZhuGuanBM.Enabled = enabled;
        }

        /// <summary>
        ///根据当前流程状态设置步骤显示
        /// </summary>
        private void SetDisplay()
        {
            //先隐藏所有
            this.tabTopInfo.Visible = false;
            this.gvList.Visible = false;
            this.tabUserInfo.Visible = false;
            this.trYHZGBM.Visible=(BusinessTool.WType==2);
            //根据来函显示面板
            //根据来函类型及当前流程显示意意见量
            if (this.LaiHanLC == eLaiHanLCBH.未登记)
            {
                this.gvList.Visible = true;
                this.tabUserInfo.Visible = true;
                SetEnabled(true);
            }
            else if (this.LaiHanLC == eLaiHanLCBH.预登记)
            {
                this.gvList.Visible = true;   
                this.tabUserInfo.Visible = true;       
                SetEnabled(true);
            }
            else if (this.LaiHanLC == eLaiHanLCBH.登记)
            {
                this.gvList.Visible = true;   
                this.tabUserInfo.Visible = true;
                this.gvList.Columns[3].Visible = false;
                SetEnabled(false);
            }
            else if ((int)this.LaiHanLC >= (int)eLaiHanLCBH.业务员)
            {
                this.tabTopInfo.Visible = true;
                this.gvList.Visible = true;
                this.tabUserInfo.Visible = this.IsXXXX;
                this.tabTopInfo.Visible = !this.IsXXXX;
                this.gvList.Columns[3].Visible = false;
                SetEnabled(false);
            }
        }

        /// <summary>
        /// 提交验证
        /// </summary>
        ValidateRS IUCLHOperate.Validate()
        {
            ValidateRS rs = new ValidateRS();
            if (this.dtSource==null||this.dtSource.Rows.Count < 2)
            {
                rs.Msg = "请选择好要合并的用户。";
                return rs;
            }
            if (this.txtYongHuH.Text == "")
            {
                rs.Msg = "请输入新用户号！";
                return rs;
            }
            if (this.txtYongHuH.Text.Length != 7)
            {
                rs.Msg = "用户号的长度应为7位！";
                return rs;
            }
            //判断用户号是否重复
            if (!this.ExistsYongHu(this.txtYongHuH.Text))
            {
                if (new QS_YG_YONGHUXXBLL().SelectQS_YG_YONGHUXXesDynamic(string.Format("I_JLZT=0 and S_YONGHUH='{0}'", this.txtYongHuH.Text), null).Rows.Count > 0)
                {
                    rs.Msg = "该用户号系统中已有使用,请更换！";
                    return rs;
                }
            }
            if (this.txtYongHuM.Text == "")
            {
                rs.Msg = "用户名不能为空！";
                return rs;
            }
            if (this.cmbXingZhengQ.Text == "")
            {
                rs.Msg = "请选择行政区！";
                return rs;
            }
            if (this.cmbYWY.Text == "")
            {
                rs.Msg = "请选择业务员！";
                return rs;
            }
            if (this.txtDiZhi.Text == "")
            {
                rs.Msg = "用户地址不能为空！";
                return rs;
            }
            if (this.txtYouBian.Text == "")
            {
                rs.Msg = "邮编不能为空！";
                return rs;
            }
            if (this.txtYSJ.Text == "")
            {
                rs.Msg = "用水价不能为空！";
                return rs;
            }
            if (!PageTools.ValidateString(this.txtYSJ.Text, PageTools.eValidateType.水价))
            {
                rs.Msg = "请输入正确的用水价！";
                return rs;
            }
            //如果为托收,需要填写银行账号,开户银行,开户户名
            if (this.cbTuoShou.Checked)
            {
                if (this.txtKaiHuYH.Text == "")
                {
                    rs.Msg = "开户银行不能为空！";
                    return rs;
                }
                if (this.txtKaiHuZH.Text == "")
                {
                    rs.Msg = "银行账号不能为空！";
                    return rs;
                }
                if (this.txtKaiHuM.Text == "")
                {
                    rs.Msg = "开户户名不能为空！";
                    return rs;
                }
                if (!PageTools.ValidateString(this.txtKaiHuZH.Text, PageTools.eValidateType.数字))
                {
                    rs.Msg = "请输入正确的银行账号！";
                    return rs;
                }
            }
            rs.IsSuccess = true;
            return rs;
        }

        /// <summary>
        /// 判断是否需要变更
        /// </summary>
        /// <returns></returns>
        public ValidateRS ValidateNeedBG(YS_LH_LAIHANXX laihanxx)
        {
            ValidateRS rs = new ValidateRS();

            rs.IsSuccess = true;
            return rs;
        }

        /// <summary>
        /// 清空数据
        /// </summary>
        public void ClearInfo()
        {
            this.txtShouLiRQ.Text = "";
            this.txtYeWuY.Text = "";
            this.dtSource = null;
            this.gvList.DataSource = null;
            this.gvList.DataBind();
            this.txtDiZhi.Text = "";
            this.txtHeTongH.Text = "";
            this.txtKaiHuM.Text = "";
            this.txtKaiHuYH.Text = "";
            this.txtKaiHuZH.Text = "";
            this.txtLianXiBM.Text = "";
            this.txtLianXiDH.Text = "";
            this.txtLianXiR.Text = "";
            this.txtYeWuY.Text = "";
            this.txtYongHuH.Text = "";
            this.txtYongHuM.Text = "";
            this.txtYouBian.Text = "";
            this.txtYSJ.Text = "";
            this.cmbHangYeLX.SelectedIndex = 0;
            this.cmbXingZhengQ.SelectedIndex = 0;
            this.cmbYWY.SelectedIndex = 0;
            this.cbTuoShou.Checked = false;
            this.txtCaiWuDZ.Text = "";
            this.txtCaiWuHM.Text = "";
            this.txtCaiWuYB.Text = "";
        }

        /// <summary>
        /// 判断是否已存在
        /// </summary>
        /// <param name="yonghuh">用户号</param>
        public bool ExistsYongHu(string yonghuh)
        {
            //判断是否已经存在
            if (this.dtSource == null || this.dtSource.Rows.Count == 0)
            {
                return false;
            }
            foreach (DataRow row in this.dtSource.Rows)
            {
                if (row["S_YONGHUH"].ToString() == yonghuh)
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 将对应用户号用户添加到LIST
        /// </summary>
        /// <param name="yonghuh">用户号</param>
        public void AddYongHu(string yonghuh)
        {
            //判断是否已经存在
            if (this.dtSource == null)
            {
                this.dtSource = new DataTable();
                this.dtSource.Columns.Add("ID");
                this.dtSource.Columns.Add("S_YONGHUH");
                this.dtSource.Columns.Add("S_YONGHUM");
                this.dtSource.Columns.Add("S_DIZHI");
            }
            DataRowCollection drc = new QS_YG_YONGHUXXBLL().SelectQS_YG_YONGHUXXesDynamic("I_JLZT=0 AND S_YONGHUH=" + yonghuh, null).Rows;
            if (drc.Count != 1)
            {
                throw new Exception(yonghuh + "用户不存在或有重复,请检查数据");
            }
            else
            {
                //加载第一个用户信息
                if (this.dtSource.Rows.Count == 0)
                {
                    DataRow dr2 = drc[0];
                    this.txtYongHuM.Text = Convert.ToString(dr2["S_YONGHUM"]);
                    this.cmbZhuGuanBM.Value = Convert.ToString(dr2["S_BUMENBH"]);
                    this.txtYSJ.Text = Convert.ToString(dr2["N_SHUIJIA"]);
                    this.cmbYWY.Value = Convert.ToString(dr2["S_YEWUY"]);
                    this.cmbXingZhengQ.Value = Convert.ToString(dr2["S_XINGZHENGQBH"]);
                    this.cmbHuanXianBJ.Value = dr2["S_HUANXIANBJ"].ToString();
                    this.cmbQuShuiYT.Value = dr2["S_QUSHUIYTBH"].ToString();
                    this.cmbHangYeLX.Value = Convert.ToString(dr2["S_HANGYEBH"]);
                    this.cmbLiuYu.Value = dr2["S_LIUYUBH"].ToString();
                    this.cmbShuiLiFP.Value = dr2["S_FENPIANBH"].ToString();
                    this.cmbShuiZiYFQ.Value = dr2["S_SHUIZIYBH"].ToString();
                    this.cmbZhuangBiaoJL.Value = dr2["S_ZHUANGBIAOJL"].ToString();

                    this.txtLianXiR.Text = Convert.ToString(dr2["S_LIANXIR"]);
                    this.txtLianXiBM.Text = Convert.ToString(dr2["S_LIANXIBM"]);
                    this.txtYouBian.Text = Convert.ToString(dr2["S_YOUBIAN"]);
                    this.txtLianXiDH.Text = Convert.ToString(dr2["S_DIANHUA"]);
                    this.txtDiZhi.Text = Convert.ToString(dr2["S_DIZHI"]);
                    this.txtCaiWuHM.Text = Convert.ToString(dr2["S_CAIWUHM"]);
                    this.txtCaiWuDZ.Text = Convert.ToString(dr2["S_CAIWUDZ"]);
                    this.txtCaiWuYB.Text = Convert.ToString(dr2["S_CAIWUYB"]);

                    this.txtKaiHuM.Text = Convert.ToString(dr2["S_KAIHUHM"]);
                    this.txtKaiHuYH.Text = Convert.ToString(dr2["S_KAIHUYH"]);
                    this.txtKaiHuZH.Text = Convert.ToString(dr2["S_KAIHUH"]);
                    this.cbTuoShou.Checked = (Convert.ToInt32(dr2["I_BIAOSHI"]) == 1);
                    this.txtHeTongH.Text = Convert.ToString(dr2["S_HETONGH"]);
                }
                DataRow dr = this.dtSource.NewRow();
                dr["ID"] = drc[0]["ID"];
                dr["S_YONGHUH"] = drc[0]["S_YONGHUH"];
                dr["S_YONGHUM"] = drc[0]["S_YONGHUM"];
                dr["S_DIZHI"] = drc[0]["S_DIZHI"];
                this.dtSource.Rows.Add(dr);
                this.gvList.DataSource = this.dtSource;
                this.gvList.DataBind();
            }
        }

        /// <summary>
        /// 根据来函加载信息
        /// </summary>
        /// <param name="laihanxx"></param>
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            if (laihanxx.ID == 0)
            {
                this.LaiHanLC = eLaiHanLCBH.未登记;
                SetDisplay();
                return;
            }
            else
            {
                this.LaiHanLC = (eLaiHanLCBH)Enum.Parse(typeof(eLaiHanLCBH), laihanxx.I_LIUCHENGBH.ToString());
                SetDisplay();
            }            
            //获取并户原用户列表
            QS_LH_YONGHUTZProcess bllT = new QS_LH_YONGHUTZProcess();
            this.dtSource = bllT.SelectQS_LH_YONGHUTZsDynamic("S_LAIHANBH=" + laihanxx.S_LAIHANBH + " and I_YUANYONGH=1", null);
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind(); 
            //获取并户结果用户
            DataRowCollection drc= bllT.SelectQS_LH_YONGHUTZsDynamic("S_LAIHANBH=" + laihanxx.S_LAIHANBH + " and I_YUANYONGH=0", null).Rows;
            if (drc.Count > 0)
            {
                DataRow drTemp = drc[0];
                this.txtDiZhi.Text = Convert.ToString(drTemp["S_DiZhi"]);
                this.txtHeTongH.Text = Convert.ToString(drTemp["S_HETONGH"]);
                this.txtKaiHuM.Text = Convert.ToString(drTemp["S_KAIHUHM"]);
                this.txtKaiHuYH.Text = Convert.ToString(drTemp["S_KAIHUYH"]);
                this.txtKaiHuZH.Text = Convert.ToString(drTemp["S_KAIHUH"]);
                this.txtLianXiBM.Text = Convert.ToString(drTemp["S_LIANXIBM"]);
                this.txtLianXiDH.Text = Convert.ToString(drTemp["S_DIANHUA"]);
                this.txtLianXiR.Text = Convert.ToString(drTemp["S_LIANXIR"]);
                this.txtYongHuH.Text = Convert.ToString(drTemp["S_YONGHUH"]);
                this.txtYongHuM.Text = Convert.ToString(drTemp["S_YONGHUM"]);
                this.txtYouBian.Text = Convert.ToString(drTemp["S_YOUBIAN"]);
                this.txtYSJ.Text = Convert.ToString(drTemp["N_SHUIJIA"]);
                this.cbTuoShou.Checked = (Convert.ToInt32(drTemp["I_BIAOSHI"]) == 1);
                this.cmbXingZhengQ.Value = Convert.ToString(drTemp["S_XINGZHENGQBH"]);
                this.cmbYWY.Value = Convert.ToString(drTemp["S_YEWUY"]);
                //QS_YG_YONGHUXX a = new QS_YG_YONGHUXX();
                this.cmbHuanXianBJ.Value = Convert.ToString(drTemp["S_HUANXIANBJ"]);
                this.cmbLiuYu.Value = Convert.ToString(drTemp["S_LIUYUBH"]);
                this.cmbQuShuiYT.Value = Convert.ToString(drTemp["S_QUSHUIYTBH"]);
                this.cmbShuiLiFP.Value = Convert.ToString(drTemp["S_FENPIANBH"]);
                this.cmbShuiZiYFQ.Value = Convert.ToString(drTemp["S_SHUIZIYBH"]);
                this.cmbZhuangBiaoJL.Value = Convert.ToString(drTemp["S_ZHUANGBIAOJL"]);
                this.cmbZhuGuanBM.Value = Convert.ToString(drTemp["S_BUMENBH"]);
                //获取受理日期等
                drTemp = new SpHelper().P_YS_LHGETINFODETAIL(laihanxx.S_LAIHANBH, (int)laihanxx.I_LAIHANLX).Tables[0].Rows[0];
                this.txtShouLiRQ.Text = drTemp["D_SHOULIRQ"] == DBNull.Value ? "" : Convert.ToDateTime(drTemp["D_SHOULIRQ"]).ToString("yyyy-MM-dd");
                this.txtYeWuY.Text = Convert.ToString(drTemp["S_YWY"]);
            }
        }

        /// <summary>
        /// 获取来函主表信息
        /// </summary>
        /// <param name="liuchengzt">0:收件 1:收件并登记</param>
        /// <param name="msg">输出消息,正常为空</param>
        /// <returns>null:验证失败 !null:成功返回</returns>
        public YS_LH_LAIHANXX GetLAIHANXX(int laihanid, int liuchengzt, out string msg)
        {
            YS_LH_LAIHANXX laihan = new YS_LH_LAIHANXX();
            string laihanbh = "";
            string xukebh = "";
            msg = "";
            if (laihanid == 0)
            {
                laihan.ID = 0;
                string zd, glk, ywy;
                PageTools.GetLHDJZDGLKYWY(this.txtYongHuH.Text, out zd, out glk, out ywy);
                laihan.S_ZHANDIANBH = zd;
                laihan.S_GUANLIKBH = glk;
                laihan.I_YWY = int.Parse(this.cmbYWY.Value.ToString());//ywy
                laihan.S_YWY = this.cmbYWY.Text;//BusinessTool.GetYWYName(ywy);
                //laihan.S_YHYWY = ywy;
                //DataSet numset = new SpHelper().P_YS_LH_XUKEBH(glk, (int)this.LaiHanLX, 0, (BusinessTool.GetWaterYM() / 100).ToString(), out xukebh, out laihanbh);
                //DataSet numset = new SpHelper().P_YS_LH_XUKEBH(BusinessTool.QSGLKH, (int)this.LaiHanLX, 0, (BusinessTool.GetWaterYM() / 100).ToString(), out xukebh, out laihanbh);
                new SpHelper().P_ALL_LH_BHSC(BusinessTool.WType, (int)this.LaiHanLX, BusinessTool.GetWaterYM() / 100, out laihanbh);
                laihan.I_XT = BusinessTool.WType;
                laihan.D_SHURURQ = DateTime.Now;
                laihan.D_LAIHANRQ = DateTime.Now;
                laihan.I_JLZT = 0;
                laihan.I_LAIHANLX = (int)this.LaiHanLX;
                laihan.I_SHURUR = LoginInfo.CurrentUser.UserID;
                laihan.I_AUTOTYPE = 0;
                laihan.S_LAIHANBH = laihanbh;
                laihan.S_BEIYONG1 = xukebh;
                laihan.S_XUKEBH = xukebh;
                //laihan.S_GUANLIKBH = this.GuanLiKBH;
                laihan.S_YONGHUBH = this.txtYongHuH.Text;
                laihan.S_YONGHUM = this.txtYongHuM.Text;
                //laihan.S_ZHANDIANBH = this.ZhanDianBH;
                laihan.I_Y = BusinessTool.GetWaterYM() / 100;
                laihan.I_M = BusinessTool.GetWaterYM() % 100;
            }
            else
            {
                laihan = new YS_LH_LAIHANXXProcess().SelectYS_LH_LAIHANXX(laihanid);
            }
            //laihan.S_GUANLIKBH = this.GuanLiKBH;
            ////laihan.S_YONGHUBH = this.txtYongHuH.Text;
            //laihan.S_ZHANDIANBH = this.ZhanDianBH;
            laihan.I_LIUCHENGBH = liuchengzt;
            laihan.I_LIUCHENGZT = (int)eLaiHanLCZT.流程中;
            laihan.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            laihan.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
            //用户号取源用户之一
            //foreach (DataRow item in this.dtSource.Rows)
            //{
            //    laihan.S_YONGHUBH = item["S_YONGHUH"].ToString();
            //    break;
            //}
            return laihan;
        }

        /// <summary>
        /// 添加副表信息
        /// </summary>
        /// <returns></returns>
        public void GreateLHFB(YS_LH_LAIHANXX laihanxx)
        {
            QS_LH_BINGHU tz = new QS_LH_BINGHU();
            tz.ID = 0;
            tz.I_JLZT = 0;
            tz.S_LAIHANBH = laihanxx.S_LAIHANBH;
            tz.I_SHURUR = LoginInfo.CurrentUser.UserID;
            tz.D_SHURURQ = DateTime.Now;
            tz.I_LIUCHENGBH = laihanxx.I_LIUCHENGBH;
            tz.I_SHENPIJG = 1;
            tz.S_SHENPIYJ = laihanxx.I_LIUCHENGBH == 0 ? "预登记" : "登记";
            QS_LH_BINGHUBLL bllT = new QS_LH_BINGHUBLL();
            //插入新的登记信息
            bllT.InsertOrUpdate(tz);
        }

        /// <summary>
        /// 添加申请信息
        /// </summary>
        /// <param name="laihanxx"></param>
        public void CreateShengQingXX(YS_LH_LAIHANXX laihanxx)
        {            
            //清除用户变更表
            QS_LH_YONGHUTZProcess bllyhtz = new QS_LH_YONGHUTZProcess();
            bllyhtz.DeleteQS_LH_YONGHUTZsDynamic("S_LAIHANBH=" + laihanxx.S_LAIHANBH);
            //更新用户变更表
            List<QS_LH_YONGHUTZ> yhtzList = this.GetLHYONGHUTZ(laihanxx);
            foreach (QS_LH_YONGHUTZ item in yhtzList)
            {
                bllyhtz.InsertOrUpdate(item);
            }
        }

        /// <summary>
        /// 获取来函用户调整
        /// </summary>
        /// <returns></returns>
        public List<QS_LH_YONGHUTZ> GetLHYONGHUTZ(YS_LH_LAIHANXX laihanxx)
        {
            List<QS_LH_YONGHUTZ> list = new List<QS_LH_YONGHUTZ>();
            //添加原用户
            foreach (DataRow item in this.dtSource.Rows)
            {
                list.Add(CreateYuanYongHu(item, laihanxx));
            }
            //生成结果用户的原用户号
            string yuanyonghuhs = "";
            foreach (var item in list)
            {
                yuanyonghuhs = yuanyonghuhs +","+ item.S_YONGHUH;
            }
            yuanyonghuhs = yuanyonghuhs.Substring(1);
            //添加并户结果用户
            list.Add(CreateBingHuYongHu(laihanxx,yuanyonghuhs));
            return list;
        }

        /// <summary>
        /// 获取用户号(包含并户前与并户后的)
        /// </summary>
        /// <returns></returns>
        public List<string> GetYonghuhList()
        {
            List<string> list = new List<string>();
            foreach (DataRow item in this.dtSource.Rows)
            {
                list.Add(item["S_YONGHUH"].ToString());
            }
            list.Add(this.txtYongHuH.Text);
            return list;
        }

        /// <summary>
        /// 生成原用户
        /// </summary>
        /// <returns></returns>
        private QS_LH_YONGHUTZ CreateYuanYongHu(DataRow item, YS_LH_LAIHANXX laihanxx)
        {
            QS_LH_YONGHUTZ yuanyonghu = new QS_LH_YONGHUTZ();
            DataRow drTemp = new QS_YG_YONGHUXXBLL().SelectQS_YG_YONGHUXXesDynamic("I_JLZT=0 AND S_YONGHUH=" + item["S_YONGHUH"], null).Rows[0];

            yuanyonghu.ID = 0;
            yuanyonghu.S_YONGHUH = Convert.ToString(drTemp["S_YONGHUH"]);
            yuanyonghu.S_XINGZHENGQBH = Convert.ToString(drTemp["S_XINGZHENGQBH"]);
            yuanyonghu.S_YONGHUM = Convert.ToString(drTemp["S_YONGHUM"]);
            yuanyonghu.S_DIZHI = Convert.ToString(drTemp["S_DIZHI"]);
            yuanyonghu.S_YOUBIAN = Convert.ToString(drTemp["S_YOUBIAN"]);
            yuanyonghu.S_LIANXIBM = Convert.ToString(drTemp["S_LIANXIBM"]);
            yuanyonghu.S_LIANXIR = Convert.ToString(drTemp["S_LIANXIR"]);
            yuanyonghu.S_KAIHUHM = Convert.ToString(drTemp["S_KAIHUHM"]);
            yuanyonghu.S_KAIHUYH = Convert.ToString(drTemp["S_KAIHUYH"]);
            yuanyonghu.S_YEWUY = Convert.ToString(drTemp["S_YEWUY"]);
            yuanyonghu.S_YUANYONGHUH = null;
            yuanyonghu.S_CAIWUDZ = Convert.ToString(drTemp["S_CAIWUDZ"]);
            yuanyonghu.S_CAIWUYB = Convert.ToString(drTemp["S_CAIWUYB"]);
            yuanyonghu.I_JLZT = Convert.ToDecimal(drTemp["I_JLZT"]);
            yuanyonghu.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            yuanyonghu.S_BUMENBH = Convert.ToString(drTemp["S_BUMENBH"]);
            yuanyonghu.S_DIANHUA = Convert.ToString(drTemp["S_DIANHUA"]);
            yuanyonghu.S_LIUYUBH = Convert.ToString(drTemp["S_LIUYUBH"]);
            yuanyonghu.S_SHUIZIYBH = Convert.ToString(drTemp["S_SHUIZIYBH"]);
            yuanyonghu.S_FENPIANBH = Convert.ToString(drTemp["S_FENPIANBH"]);
            yuanyonghu.S_HUANXIANBJ = Convert.ToString(drTemp["S_HUANXIANBJ"]);
            yuanyonghu.S_QUSHUIYTBH = Convert.ToString(drTemp["S_QUSHUIYTBH"]);
            yuanyonghu.S_HANGYEBH = Convert.ToString(drTemp["S_HANGYEBH"]);
            if (drTemp["N_SHUIJIA"] != DBNull.Value)
            {
                yuanyonghu.N_SHUIJIA = Convert.ToDecimal(drTemp["N_SHUIJIA"]);
            }
            yuanyonghu.I_BIAOSHI = Convert.ToDecimal(drTemp["I_BIAOSHI"]);
            yuanyonghu.S_KAIHUH = Convert.ToString(drTemp["S_KAIHUH"]);
            yuanyonghu.S_ZHUSHI = Convert.ToString(drTemp["S_ZHUSHI"]);
            yuanyonghu.I_WTYPE = Convert.ToDecimal(drTemp["I_WTYPE"]);
            yuanyonghu.S_TIANJIAR = Convert.ToString(drTemp["S_TIANJIAR"]);
            yuanyonghu.D_CAOZUORQ = BusinessTool.GetDataBaseDateTime();
            yuanyonghu.S_DESTUSER = Convert.ToString(drTemp["S_DESTUSER"]);
            yuanyonghu.S_KAISHINY = Convert.ToString(drTemp["S_KAISHINY"]);
            yuanyonghu.S_JIESHUNY = Convert.ToString(drTemp["S_JIESHUNY"]);
            yuanyonghu.S_HETONGH = Convert.ToString(drTemp["S_HETONGH"]);
            yuanyonghu.S_YINHANG = Convert.ToString(drTemp["S_YINHANG"]);
            yuanyonghu.S_CAIWUHM = Convert.ToString(drTemp["S_CAIWUHM"]);
            yuanyonghu.S_ZHUANGBIAOJL = Convert.ToString(drTemp["S_ZHUANGBIAOJL"]);
            yuanyonghu.S_FEETYPE = Convert.ToString(drTemp["S_FEETYPE"]);
            yuanyonghu.S_LAIHANBH = laihanxx.S_LAIHANBH;
            yuanyonghu.I_LAIHANLX = laihanxx.I_LAIHANLX;
            yuanyonghu.I_YUANYONGH = 1;
          
            return yuanyonghu;
        }

        /// <summary>
        /// 生成并户结果用户
        /// </summary>
        /// <returns></returns>
        private QS_LH_YONGHUTZ CreateBingHuYongHu(YS_LH_LAIHANXX laihanxx,string yuanyonghuhs)
        {
            QS_LH_YONGHUTZ yhxx = new QS_LH_YONGHUTZ();            
            yhxx.D_CAOZUORQ= BusinessTool.GetDataBaseDateTime();
            yhxx.D_TIANJIARQ = yhxx.D_CAOZUORQ;
            yhxx.I_BIAOSHI = (this.cbTuoShou.Checked ? 1 : 0);
            yhxx.I_JLZT = 0;
            yhxx.I_LAIHANLX = (int)this.LaiHanLX;
            yhxx.I_WTYPE = BusinessTool.WType;
            yhxx.I_YUANYONGH = 0;
            yhxx.ID = 0;
            yhxx.N_SHUIJIA = Convert.ToDecimal(this.txtYSJ.Text);
            yhxx.S_BUMENBH =BusinessTool.WType==2?Convert.ToString(this.cmbZhuGuanBM.Value):"600";
            yhxx.S_CAIWUDZ = this.txtCaiWuDZ.Text;
            yhxx.S_CAIWUHM = this.txtCaiWuHM.Text;
            yhxx.S_CAIWUYB = this.txtCaiWuYB.Text;
            yhxx.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            yhxx.S_DESTUSER = null;
            yhxx.S_DIANHUA = txtLianXiDH.Text;
            yhxx.S_DIZHI = this.txtDiZhi.Text;
            yhxx.S_FEETYPE = null; //(this.cbTuoShou.Checked ? "1" : "0");
            yhxx.S_FENPIANBH = Convert.ToString(this.cmbShuiLiFP.Value);
            yhxx.S_HANGYEBH = Convert.ToString(this.cmbHangYeLX.Value);
            yhxx.S_HETONGH = Convert.ToString(this.txtHeTongH.Text);
            yhxx.S_HUANXIANBJ = Convert.ToString(this.cmbHuanXianBJ.Value);
            yhxx.S_JIESHUNY = null;
            yhxx.S_KAIHUH = this.txtKaiHuZH.Text;
            yhxx.S_KAIHUHM = this.txtKaiHuM.Text;
            yhxx.S_KAIHUYH = this.txtKaiHuYH.Text;
            yhxx.S_KAISHINY = BusinessTool.GetWaterYM().ToString();
            yhxx.S_LAIHANBH = laihanxx.S_LAIHANBH;
            yhxx.S_LIANXIBM = this.txtLianXiBM.Text;
            yhxx.S_LIANXIR = this.txtLianXiR.Text;
            yhxx.S_LIUYUBH = Convert.ToString(this.cmbLiuYu.Value);
            yhxx.S_QUSHUIYTBH = Convert.ToString(this.cmbQuShuiYT.Value);
            yhxx.S_SHUIZIYBH = Convert.ToString(this.cmbShuiZiYFQ.Value);
            yhxx.S_TIANJIAR = LoginInfo.CurrentUser.UserID.ToString();
            yhxx.S_XINGZHENGQBH = this.cmbXingZhengQ.Value.ToString();
            yhxx.S_YEWUY = this.cmbYWY.Value.ToString();
            yhxx.S_YINHANG = null;
            yhxx.S_YONGHUH = this.txtYongHuH.Text;
            yhxx.S_YONGHUM = this.txtYongHuM.Text;
            yhxx.S_YOUBIAN = this.txtYouBian.Text;
            yhxx.S_YUANYONGHUH = yuanyonghuhs;
            yhxx.S_ZHUANGBIAOJL = Convert.ToString(this.cmbZhuangBiaoJL.Value);
            yhxx.S_ZHUSHI = null;            
            return yhxx;          
        }

        #endregion
        
    }
}